<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IPagedList<Link>>" %>
<%@ Import Namespace="MvcPaging"%>
<%@ Import Namespace="BaLs.Models"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
	<title>Index</title>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">    
<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript" language=javascript>

    function deleteLink(divLoc) 
      {
        deleteLink=confirm('This will delete the link permenantly, Continue ?');

        if (deleteLink)
        {
            $.ajax(
                {
                 type: "POST",
                 url: "/Link/delete/" + divLoc,
                 data:"ids=" + divLoc,
                success: function(result)
                 {
                    document.getElementById(divLoc).innerHTML = "";           
                 },
                error: function(req, status, error) 
                 {
                  alert("Sorry! We could not process the delete request right now!");
                 }

              });
        }                    
    
    }


</script>

    <h2><%=ViewData["Message"]%> </h2>
<div id="load" align="center"><img src="images/loading.gif" width="28" height="28" align="absmiddle"/></div>
    
    <br/>
     <% 
        if(Session["user"] != null)
        {
         using (Html.BeginForm("Create","Link")) {%>        
        <fieldset>
            <legend>Add new url</legend>           
            <p>
                <label for="url">URL:</label>
                <%= Html.TextBox("url") %>
                <%= Html.ValidationMessage("url", "*") %>
                <%= Html.Hidden("state","0") %>
                <input type="submit" value="Create" />
            </p>            
        </fieldset>     
    <% } %>
        <p><%=Html.ActionLink("Grab them from Delicious!","DeliciousImport") %></p>
     <%  }%>
<%-- <% foreach (var item in Model) { %>
<div class="box" id="<%= Html.Encode(item.link_id) %>">
    <div class="text"><span><%= Html.Encode(item.title) %></span><br/>
      <a href="<%= Html.Encode(item.url) %>" target="_blank"><%= Html.Encode(item.url) %></a>
      <div class="tags">
      <%foreach (var tag in item.Tags)
        { %>
      <font size="2"><%= Html.Encode(tag.tag_desc)%></font>
      <%} %></div>
      <div class="date"><%= Html.Encode(item.create_date) %></div>
    </div>
    <%if (Session["user"] != null)
      {%>
    <div class="edit"><a href="Link/edit/<% =Html.Encode(item.link_id) %>">Edit</a></div>
    <a href="#" onclick="deleteLink(<%= Html.Encode(item.link_id) %>);"><img src="../../Content/delete.png" border="0" title"Delete this"></a>
    
    <%} %>
  </div>
 <div class="clear"></div>
  <% } %>--%>
  
  <!--New design -->
  <p>
    <% foreach (var item in Model){ %>
      <div id="<%= Html.Encode(item.link_id) %>">
         <%=Html.Encode(item.title) %>
       <br /><font size=2><a href="<%=Html.Encode(item.url) %>" target=_blank> <%=Html.Encode(item.url) %></a></font> 
       <font size=1 style="background-color:Silver;"><a href="<%=Html.Encode(item.url) %>"  class="websnapr">Preview</a></font>
       <br /> <font size=2><b>Tags</b></font>
       <% foreach(var tag in item.Tags) { %>
        <font class=tag><%=Html.Encode(tag.tag_desc)%></font>
         <% }%>  
         <br /><div class="date">Last updated :<%=Html.Encode(item.create_date) %> 
                by <a href="<%=item.users[0].userid.ToString()%>"><%=item.users[0].name.ToString() %></a> <%=item.users.Count.ToString()%></div>            
            
            <br />
            <%if (Session["user"] != null)
               {%>
                <font size="1" style="background-color:Gray;color:Maroon;font:bold;">
                    <a href="#" onclick="deleteLink(<%= Html.Encode(item.link_id) %>);">DELETE</a></font> | 
                <font size="1" style="background-color:Gray;color:Maroon;font:bold;">  
                    <a href="/Link/Edit/<%= Html.Encode(item.link_id) %>">EDIT</a> </font>            
            <% } %>   
       <hr/>       
       </div>
    <%} %>   
          
    </p>
     <div class="pager">
		<%= Html.Pager(ViewData.Model.PageSize, ViewData.Model.PageNumber, ViewData.Model.TotalItemCount)%>
	</div>
  <!--end of new design -->
</asp:Content>

